package com.fenghen.demo01.test;

import java.util.ArrayList;
import java.util.List;

public class NormalThreadsExample {

    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();

        List<Thread> threads = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            final int taskId = i;
            Thread thread = new Thread(() -> {
                long sum = 0;
                for (int j = 1; j <= 1000000000; j++) {
                    sum += j;
                }
                System.out.println("Thread " + taskId + " calculated sum: " + sum);
            });
            threads.add(thread);
            thread.start();
        }

        // 等待所有线程完成
        for (Thread thread : threads) {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        long endTime = System.currentTimeMillis();
        System.out.println("Normal Threads Execution Time: " + (endTime - startTime) + " ms");
    }
}